package com.xiaolin.schedule.java;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName TestScheduledExecutorService
 * @Description TODO
 * @Detail 使用线程池实现任务调度
 * @Author MyPC
 * @Date 2020/9/27
 * @Version 1.0
 */
public class TestScheduledExecutorService {
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        };
        //创建一个单线程的线程池
        ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
        //参数1是线程、参数2是延迟多少时间执行，参数3是执行周期，参数4是延迟时间和执行周期的时间单位,
        service.scheduleAtFixedRate(runnable,1L, 1, TimeUnit.SECONDS);
    }
}
